/**
 * 套保类资产,时间搜索
 */

import React, {Component} from 'react';
import {connect} from 'dva';
import {routerRedux} from 'dva/router';
import {
	Card, Row, Col,message,
	Form,DatePicker,Button,
 } from 'antd';
import DateRangePicker  from '../../../../components/common/dateSearch/DatePicker';
import styles from './datesearch.less'

const FormItem = Form.Item;
const RangePicker = DatePicker.RangePicker;

const Datesearch = ({tag,dispatch,begindate,enddate,location:{pathname,query}})=>{

	console.log("location>>>date",location,query,begindate,enddate,);
	if(location.hash.indexOf("begindate") > -1){
		const arr = location.hash.split('?')[1].split('&')
		var BD = arr[0].split("=")[1];
		var ED = arr[2].split("=")[1];
	}
  const queryData=() => {
		console.log('beginDate>>>',begindate,'endDate>>>',enddate)
		if(begindate == "" || enddate == "" || begindate == "Invalid date"){
			message.warning('请选择时间1');
			return;
		}else{
			dispatch({
				type: `${tag}/changeRouter`,
				payload: {
					table:`if${tag}`,
					pagesize:15,
					currentpage:1,
					begindate:begindate || BD,
					enddate:enddate || ED
				}
			})
			dispatch({
				type: `${tag}/setState`,
				payload: {
					'isRefresh':0
				}
			})
		}
		

	}
  return (
    <div className={styles.searchbar}>
      <Form layout="inline" style={{width:850}}>
      	<Row type="flex" justify="between" align="middle">
      		<Col span={6}>
      			<FormItem >
		          <DateRangePicker
								dispatch={dispatch}
								tag={tag}
								location={location}
								begindate={begindate || ''}
								enddate={enddate || ''}
		          />
		        </FormItem>
      		</Col>
      		<Col span={4}>
      			<Button type="primary" onClick={queryData}>
	          查询
	        </Button>
      		</Col>
      	</Row>
      </Form>
    </div>
  )
}

export default connect(({})=>({}))(Datesearch)
